<template>
	<view class="border-top">
		<view class="px-2 mb-3">
			<class-head :info="userInfo" :school="school" :dl="dl" :status="sbstatus"></class-head>
		</view>
		<view class="px-25 mb-3">
			<class-card>
				<view class="flex flex-wrap">
					<view class="text-center" style="width: 25%;" v-for="(item, index) in stuList" :key="index">
						<navigator :url="item.path">
							<image :src="item.iconUrl" style="width: 104rpx;height: 104rpx;" mode=""></image>
							<view class="color333 font-weight-500 font26">{{ item.name }}</view>
						</navigator>
					</view>
				</view>
			</class-card>
		</view>
		<view class="px-25 mb-3">
			<class-card>
				<view class="flex flex-wrap">
					<view class="text-center mb-2" style="width: 25%;" v-for="(item, index) in xgList" :key="index">
						<navigator :url="item.path">
							<image :src="item.iconUrl" style="width: 104rpx;height: 104rpx;" mode=""></image>
							<view class="color333 font-weight-500 font26">{{ item.name }}</view>
						</navigator>
					</view>
				</view>
			</class-card>
		</view>
		<view class="px-25 border-top">
			<view class="p-28 color333 font30 font-weight-bold mb-2 pb-0 pt-2">教师</view>
			<view class="flex flex-wrap">
				<view class="text-center mb-1" style="width: 175rpx;" v-for="(item, index) in list" :key="index">
					<image src="../../static/img/ic_default_head.png" class="rounded-circle"
						style="width: 100rpx;height: 100rpx;"
						v-if="item.head_pic == 'http://api.sxxat.cn:443' ||item.head_pic == null||item.head_pic == ''|| item.head_pic == 'http://api.sxxat.cn:443null' || item.head_pic == 'http://localhost:8888'"
						mode=""></image>
					<image :src="item.head_pic" class="rounded-circle" style="width: 100rpx;height: 100rpx;" v-else
						mode=""></image>
					<view class="font-weight-500 font26 color666">{{ item.user_name }}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import classHead from '../../components/common/class-head.vue';
	import classCard from '../../components/common/class-card.vue';
	export default {
		data() {
			return {
				userInfo: {},
				school: '',
				stuList: [{
						name: '上课模式',
						iconUrl: '../../static/img/ic_class_mode.png',
						path: './classmode/classmode'
					}, {
						name: '考勤',
						iconUrl: '../../static/img/ic_class_clock.png',
						path: '../keep/keep'
					},
					{
						name: '定位',
						iconUrl: '../../static/img/ic_class_location.png',
						path: '../location/location'
					},
					// {
					// 	name: '定位',
					// 	iconUrl: '../../static/img/ic_class_location.png',
					// 	path: '../location/testmap/testmap'
					// },
					// { name: '课程表', iconUrl: '../../static/img/ic_class_location7.png', path: '../curriculum/curriculum' },
					// { name: '菜谱', iconUrl: '../../static/img/ic_class_location6.png', path: '../menu/menu' }
					{
						name: '班级风采',
						iconUrl: '../../static/img/ic_class_location7.png',
						path: '../curriculum/curriculum'
					},
					{
						name: '校园风采',
						iconUrl: '../../static/img/ic_class_location6.png',
						path: '../menu/menu'
					}
				],
				xgList: [{
						name: '学习通知',
						iconUrl: '../../static/img/ic_class_location3.png',
						path: './task/task'
					},
					// {
					// 	name: '解答',
					// 	iconUrl: '../../static/img/ic_class_location5.png',
					// 	path: './answer/answer'
					// },
					{
						name: '成绩',
						iconUrl: '../../static/img/ic_class_location4.png',
						path: './achievement/achievement'
					},
					{
						name: '请假',
						iconUrl: '../../static/img/ic_class_location8.png',
						path: '../leave/leave'
					},
					{
						name: '健康功能',
						iconUrl: '../../static/img/ic_class_body.png',
						path: '../health/health'
					},
					{
						name: '闹铃',
						iconUrl: '../../static/img/ic_class_location8.png',
						path: '../alarm/alarm'
					}
				],
				list: [],
				dl: '未知',
				sbstatus: "未知状态"
			};
		},
		components: {
			classHead,
			classCard
		},
		onLoad(options) {
			console.log(uni.getStorageSync('userInfo').user_id);
			console.log(options);
			this.userInfo = uni.getStorageSync('userInfo').class_info[options.index];
			this.getInfo(options.classId);
			this.getDeviceDl(options.imei, options.index);
			this.getDeviceInfo(options.imei);
			uni.setStorage({
				key: 'classcode',
				data: options.id
			});
			uni.setStorage({
				key: 'imei',
				data: options.imei
			});
			uni.setStorage({
				key: 'classUserId',
				data: options.userId
			});
			uni.setStorage({
				key: 'classId',
				data: options.classId
			});
		},
		methods: {
			getInfo(id) {
				let this_ = this;
				let opts = {
					url: 'SearchBj.shtml'
				};
				let param = {
					token: uni.getStorageSync('userInfo').token,
					class_id: id
				};
				this_.$http.httpRequest(opts, param).then(
					res => {
						console.log(res.data);
						if (res.data.code == '200') {
							this_.school = res.data.data.school;
							this_.list = res.data.data.teacher;
						} else {
							uni.showToast({
								icon: 'none',
								title: res.data.msg
							});
						}
					},
					error => {
						console.log(error);
					}
				);
			},
			getDeviceDl(imei, index) {
				let this_ = this;
				let opts = {
					url: 'device/elec?serialNo=' + imei + '&AuthToken=' + uni
						.getStorageSync('userInfo').token
				};
				let param = {
					serialNo: imei,
					AuthToken: uni.getStorageSync('userInfo').token
				};
				this_.$http.httpDeveiceRequest(opts, param).then(
					res => {
						// console.log(res.data.ReturnData.deviceStatus);
						if (res.data.ReturnMsg == "success") {
							this_.dl = res.data.ReturnData.message
						}

					},
					error => {
						console.log(error);
					}
				);
			},
			getDeviceInfo(imei) {
				let this_ = this;
				let opts = {
					url: 'device/devicestatus?serialno=' + imei,
				};
				let param = {
					serialno: imei
				};
				this_.$http.httpDeveiceRequest(opts, param).then(
					res => {
						console.log(res.data.ReturnData.deviceStatus);
						if (res.data.ReturnMsg == "success") {
							let status = res.data.ReturnData.deviceStatus;
							if (status == "ONLINE") {
								this.sbstatus = "在线"
							} else {
								this.sbstatus = "离线"
							}
						} else {
							this.sbstatus = "离线"
						}

					},
					error => {
						console.log(error);
					}
				);
			}
		}
	};
</script>

<style></style>
